require 'shapelib'

class ShapeFile

  attr_reader :file, :fields, :maxbound, :minbound, :shape_type, :shapes
  
  def initialize(file)
    @file = file
    ShapeLib::ShapeFile::open(@file) { |file|
      @fields = file.fields.inject({}) do |hsh, field|
        hsh[field] = { :name => field, :decimals => file.field_decimals(field),
          :type => file.field_type(field), :width => file.field_width(field),
          :index => file.field_index(field) }
        hsh
      end
      @maxbound = file.maxbound
      @minbound = file.minbound
      @shape_type = file.shape_type
      @shapes = []
      file.each { |shape| @shapes << shape }
    }
  end
  
end